﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.ProductionManage;
using ProduceBasicData.Api.Application.Command.ProductionManage.Technology;
using ProduceBasicData.Api.DTO;
using ProduceBasicData.Api.DTO.ProductionManage;
using ProduceBasicData.Domain.WarehouseManage;
using ProduceBasicData.ErrorCode;
using System.Security.Policy;

namespace ProduceBasicData.Api.Controllers.Report
{
    /// <summary>
    /// 工艺技术相关控制器 - 工单生产任务处理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TechnologyController : ControllerBase
    {
        private readonly IMediator _mediator;
        private readonly ILogger<TechnologyController> _logger;

        public TechnologyController(IMediator mediator, ILogger<TechnologyController> logger)
        {
            _mediator = mediator;
            _logger = logger;
        }
        /// <summary>
        /// 获取工单对应的工艺路线
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]

        public async Task<ApiResult<Responsedto>> GetOrderCraft([FromQuery]GetWorkOrderProcessStatusCommand request)
        {
            return await _mediator.Send(request);
        }
        /// <summary>
        /// 入库操作
        /// </summary>
        /// <param name="request">入库请求</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> EndTechnology(EndTechnologyCommand request)
        {
            return await _mediator.Send(request);
        }
        /// <summary>
        /// 获取对应的工序
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<List<ProcessDto>>> GetProcess(ProcessWorkOrderCommand request)
        {
            return await _mediator.Send(request);
        }
        /// <summary>
        /// 仓库下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<Warehouse>>> GetWareHouse()
        {
            GetWareHouseCommand request= new GetWareHouseCommand();
            return _mediator.Send(request);
        }
        /// <summary>
        /// 仓库库区下拉框
        /// </summary>
        /// <param name="WarehouseId">仓库编号</param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<WarehouseZone>>> GetWarehouseZone(int WarehouseId)
        {
            GetWarehouseZoneCommand request=new GetWarehouseZoneCommand();
            request.WarehouseId = WarehouseId;
            return _mediator.Send(request);
        }
        /// <summary>
        /// 仓库库区库位下拉框
        /// </summary>
        /// <param name="ZoneId">仓库库位编号</param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<StorageLocation>>> GetStorageLocation(int ZoneId)
        {
            GetStorageLocationCommand request = new GetStorageLocationCommand();
            request.ZoneId = ZoneId;
            return _mediator.Send(request);
        }
        /// <summary>
        /// 对工单的工序进行通过
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> PassProcess(CreateNodeCommand request)
        {
            return await _mediator.Send(request);
        }
    }
}
